<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="../js/jquery.js"></script>
    <script>
        // Promise的封装
        function request(url) {
            return new Promise((resolve, reject) => {
                $.ajax({
                    url: url,
                    success(data) {
                        resolve(data)
                    },
                    error(err) {
                        reject(err)
                    }
                })
            })
        }

        // 额外定义一个async函数
        async function fn() {
            // 第一个await没有响应结束,第二个await是不会响应的
            const res1 = await request('http://localhost:3000/data')
            const res2 = await request('http://localhost:3000/data1')
            const res3 = await request('http://localhost:3000/data2')
            console.log(res1);
            console.log(res2);
            console.log(res3);
        }
        fn()
        
    </script>
</body>

</html>